package org.opengauss.datachecker.extract.task;

import org.opengauss.datachecker.common.config.ConfigCache;
import org.opengauss.datachecker.common.constant.ConfigConstants;
import org.opengauss.datachecker.common.entry.enums.CheckMode;
import org.opengauss.datachecker.common.entry.enums.DataBaseType;

import java.util.Objects;

/**
 * ResultSetHandlerFactory
 * 
 * Factory class for creating ResultSetHandler instances based on the database type.
 * Supports different database types and check modes.
 * 
 * @authour ：wangchao
 * @date ：Created in 2022/9/19
 * @since ：11
 */
public class ResultSetHandlerFactory {
    /**
     * Create ResultSetHandler based on the given database type.
     *
     * @param databaseType the type of the database
     * @return a ResultSetHandler instance
     */
    public ResultSetHandler createHandler(DataBaseType databaseType) {
        Boolean supplyZero = ConfigCache.getBooleanValue(ConfigConstants.FLOATING_POINT_DATA_SUPPLY_ZERO);
        CheckMode checkMode = ConfigCache.getCheckMode();

        if (Objects.equals(databaseType, DataBaseType.MS)) {
            return new MysqlResultSetHandler();
        } else if (Objects.equals(databaseType, DataBaseType.OG)) {
            if (Objects.equals(CheckMode.CSV, checkMode)) {
                return new OpenGaussCsvResultSetHandler();
            } else {
                return new OpenGaussResultSetHandler(supplyZero);
            }
        } else if (Objects.equals(databaseType, DataBaseType.O)) {
            return new OracleResultSetHandler();
        } else if (Objects.equals(databaseType, DataBaseType.SS)) {
            return new SqlServerResultSetHandler();
        } else {
            return null;
        }
    }
}
